import Component from "../Component.js";
import Db from "../../experience/db/Db.js";
import Api from "../../experience/api/Api.js";
import Utils from "../../experience/utils/Utils.js";
import SensorUtils from "./SensorUtils.js";
import Algorithm from "../../experience/utils/Algorithm.js";
import Emitter from "../../experience/utils/Emitter.js";
import Drawer from "../../experience/drawer/Drawer.js";
import SensorEdit from "./mode/SensorEdit.js"
import SensorPreview from "./mode/SensorPreview.js"

import VentilationArrowRender from "./ventilation/VentilationArrowRender.js"

export default class SafeMonitor extends Component {
    constructor() {
        super()

        if (SafeMonitor.instance) {
            return SafeMonitor.instance;
        }
        SafeMonitor.instance = this;

        this.db = new Db();
        this.api = new Api();
        this.utils = new Utils();
        this.algo = new Algorithm();
        this.emitter = new Emitter();
        this.drawer = new Drawer();
        this.sensorUtils = new SensorUtils();
        new VentilationArrowRender();
        let edit = this.utils.getUrlParamer("edit");
        if (edit === 'true') {
            new SensorEdit();
        } else {
            this.timer();
            new SensorPreview();
        }
    }

    timer() {
        const refreshTime = 1000 * 60 * 2
        // const refreshTime = 8000
        setInterval(async () => {
            await this.sensorUtils.PositionDbRefresh()
        }, refreshTime);
    }

    template() {
    }

    control() {
    }
}
